<?php

namespace Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class BaseCommand extends Command
{
    protected $emethod = array("url","base64");
    protected $name ;

    protected function configure()
    {
        $this->setName($this->getName())
            ->addOption("encode", "e", InputOption::VALUE_OPTIONAL,"Choice a method to encode your payload: url、base64")
            ->addArgument("version", InputArgument::REQUIRED, "The version of framework")
            ->addArgument("cmd",InputArgument::REQUIRED, "Command")
        ;
    }

    protected function encode(String $method,$payload){
        if(in_array($method,$this->emethod)){
            switch ($method){
                case "url":
                    return urlencode($payload);
                case "base64":
                    return base64_encode($payload);
            }
        }else{
            die("4ny0neSec: This method is not support");
        }
    }

    public function getName()
    {
        return $this->name;
    }

}